package com.qq.common;

import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import io.swagger.models.auth.In;
import org.apache.commons.lang3.RandomUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * @desc 创建qq好码
 * @author  yule
 * @create  2019/4/2
 **/
@Component
public class QcodeCreate {
    private static Logger log = LoggerFactory.getLogger(QcodeCreate.class);
    @Autowired
    private Baseinfo_user base;

    private List<Integer>  qqpool = new ArrayList<>();

    /**
     *  创建qq号以备申请
     */
    public void init(int size){
        for(int i=size;i<100;i++){
            int aa = RandomUtils.nextInt(10000000,99999999);
            while (base.usersMap.get(aa)!=null){
                aa = RandomUtils.nextInt(10000000,99999999);
            }
            qqpool.add(aa);
        }
        log.info("QQ号备选池初始化完毕：{}",qqpool.size());
    }

    //获取一个随机QQ号，并从池中移除
    public int getQQcode(){
        int a = qqpool.remove(0);
        if(qqpool.size()<20){
            init(qqpool.size());
        }
        System.out.println("剩余数量"+qqpool.size());
        return a;
    }
}
